<template>
	<view class="wf-box">
		<view class="head" :style="{ paddingTop: navBarHeight }">
			<view class="head-np">
				<view class="back" @click="back()">
					<image src="../../static/img/chat-09.png"></image>
				</view>
				<view class="title">提现</view>
				<view></view>
			</view>
		</view>
		<view class="main">
			<view class="title">代币</view>
			<view class="item">
				<image src="../../static/img/token_1.png" mode="widthFix"></image>
				<view>USDT</view>
			</view>
			<view class="title">主网</view>
			<view class="item">
				<image src="../../static/img/wang_1.png" mode="widthFix"></image>
				<view>BNB Chain</view>
			</view>
			<view class="title">收款地址</view>
			<view class="item"><input type="text" placeholder="请输入收款地址" v-model="address" /></view>
			<!-- <view class="item">
				<image class="avatar" src="../../static/img/avatar.png" mode="widthFix"></image>
				<view class="i_right">
					<view>夜晚的星光</view>
					<view><text>ID:0x228...f6954</text>
						<image src="@/static/img/copy-icon.png" mode="widthFix"></image>
					</view>
				</view>
			</view> -->
			<view class="title">
				<text>提现金额</text>
				<text>余额：{{walletInfo.usdlBalance}}USDT</text>
			</view>
			<view class="item"><input type="number" min="10" max="1000" @blur="handleInput"
					placeholder="提现金额10~1000USDT" v-model="money" /></view>
			<view class="withdraw-tip">
				<text>注:</text>
				<text>每日只能提现1次，提现T+1到账</text>
			</view>

			<view class="btn" @click="huaz">提现</view>
			<view class="record" @click="record()">提现记录</view>
			
			<view class="premium">提现需手续费{{sxf}}%</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup-box">
				<!-- <view class="popup-title">划转</view> -->
				<!-- <view class="popup-sub">确认要删除本条草稿动态</view> -->
				<view class="popup-text">钱包密码</view>
				<input type="text" password="true" placeholder="请输入钱包密码" v-model="password" />
				<view class="popup-footer">
					<view class="cancle" @click="closePopup()">取消</view>
					<view class="confim" @click="confim()">确定</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		withdrawApply,
		getWalletInfoApi,
		getWirhdrawFee
	} from '@/api/api.js'
	import navBarMixin from '@/mixin/navBarMixin.js'
	export default {
		data() {
			return {
				money: '',
				address: '',
				password: '',
				walletInfo: '',
				sxf:'',
			}
		},
		mixins: [navBarMixin],
		onLoad(e) {
			this.getSxf()
		},
		onShow() {
			this.getWallinfo()
		},
		methods: {
			getSxf() {
				getWirhdrawFee().then(res=>{
					console.log(res);
					if (res.code == 0) {
						this.sxf = res.data
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 3000,
						})
					}
				})
			},
			async getWallinfo() {
				const res = await getWalletInfoApi()
				if (!res.code) {
					this.walletInfo = res.data
					// if(!this.walletInfo.isBindOtc) {
					// 	this.$refs.moneyPop.open()
					// }

				}
			},
			handleInput(event) {
				console.log(event);
				// let value = parseInt(event.target.value);
				this.money = this.money.replace(/[^\d]/g, '');
				let value = parseInt(this.money);
				if (value < 10 || value > 1000) {
					uni.showToast({
						title: '请输入正确的贷款金额',
						icon: 'none'
					});
					this.money = '';
				}
			},
			record() {
				uni.navigateTo({
					url: '/pages/me/extractiveRecord'
				})
			},
			closePopup() {
				this.$refs.popup.close()
				this.password = ''
			},
			huaz() {
				this.$refs.popup.open()
			},
			confim() {
				withdrawApply({
					amount: this.money,
					address: this.address,
					password: this.password
				}).then(res => {
					console.log(res);
					this.closePopup()
					if (res.code == 0) {
						uni.showToast({
							title: '提现成功!',
							icon: 'none',
							duration: 2000,
						})
						setTimeout(function() {
							uni.navigateBack()
						}, 2000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 3000,
						})
					}
				})
			},
			back() {
				uni.navigateBack()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.wf-box {
		overflow: hidden;

		.back {
			image {
				width: 20rpx;
				height: 37rpx;
			}
		}

		.head {
			position: fixed;
			z-index: 333;
			width: 100%;
			background: #fff;

			.head-np {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 96rpx;
				padding: 0 30rpx;
				box-sizing: border-box;

				.title {
					font-size: 36rpx;
					font-weight: bold;
				}
			}
		}

		.main {
			// margin-top: 126rpx;
			// margin-top: 246rpx;
			margin: 196rpx 30rpx 60rpx;
			padding: 0 30rpx 88rpx;
			background-color: white;
			border-radius: 10rpx;
			overflow: hidden;

			.title {
				font-size: 30rpx;
				margin: 30rpx 0 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				text {
					&:nth-of-type(2) {
						font-size: 26rpx;
						color: #3F93FF;
					}
				}
			}

			.item {
				height: 84rpx;
				background: #F8F8F8;
				border-radius: 10rpx;
				display: flex;
				align-items: center;
				margin-bottom: 10rpx;
				padding: 0 30rpx;

				image {
					width: 52rpx;
					// display: block;
					margin: 0 20rpx 0 0;
				}

				.avatar {
					width: 62rpx;
				}

				>view {
					font-weight: 500;
					font-size: 30rpx;
				}

				.i_right {
					view {
						&:nth-of-type(1) {
							font-weight: 500;
							font-size: 25rpx;
						}

						&:nth-of-type(2) {
							font-weight: 400;
							font-size: 22rpx;
							color: #6C6B6B;
							display: flex;
							align-items: center;
							margin-top: 6rpx;

							image {
								width: 32rpx;
								margin-left: 14rpx;
							}
						}
					}
				}

				input {
					width: 100%;
					font-size: 26rpx;
				}
			}

			.withdraw-tip {
				display: flex;
				align-items: center;
				// justify-content: space-between;
				margin-top: 20rpx;

				text {
					font-size: 26rpx;

					&:nth-of-type(1) {
						color: red;
					}

					&:nth-of-type(2) {
						margin-left: 20rpx;
						text-align: right;
						color: #666;
					}
				}
			}

			.btn {
				width: 584rpx;
				height: 84rpx;
				line-height: 84rpx;
				font-weight: 500;
				font-size: 30rpx;
				color: #FFFFFF;
				background: #3F93FF;
				border-radius: 42rpx;
				text-align: center;
				margin: 94rpx auto 20rpx;
			}

			.record {
				font-size: 26rpx;
				color: #3F93FF;
				text-align: center;
			}
			.premium {
				margin-top: 40rpx;
				color: #FF453A;
				font-size: 24rpx;
				text-align: center;
			}
		}

		.popup-box {
			width: 583rpx;
			height: 630rpx;
			border-radius: 20rpx;
			box-sizing: border-box;
			background: #fff;
			background: url('../../static/img/me-32.png') no-repeat;
			background-size: cover;
			overflow: hidden;

			.popup-title {
				font-size: 32rpx;
				color: #333;
				font-weight: bold;
				text-align: center;
				margin-top: 180rpx;
			}

			.popup-text {
				margin: 240rpx 40rpx 0;
				font-size: 28rpx;
			}

			.popup-sub {
				margin-top: 46rpx;
				color: #666;
				font-size: 28rpx;
				text-align: center;
			}

			.popup-footer {
				display: flex;
				justify-content: space-between;
				margin: 72rpx 52rpx 0;

				.cancle {
					width: 200rpx;
					line-height: 76rpx;
					text-align: center;
					border: 2rpx solid #3F93FF;
					border-radius: 40rpx;
					color: #3F93FF;
				}

				.confim {
					width: 200rpx;
					line-height: 76rpx;
					text-align: center;
					border-radius: 40rpx;
					background: #3F93FF;
					color: #fff;
				}
			}

			input {
				// width: 500rpx;
				margin: 40rpx 40rpx 0;
				padding: 0 30rpx;
				height: 84rpx;
				font-size: 28rpx;
				line-height: 84rpx;
				background: #F4F4F4;
				border-radius: 6rpx 6rpx 6rpx 6rpx;
			}
		}
	}
</style>